package com.droidclaimsurveyor.bl;

import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.Date;

import com.droidclaimsurveyor.dto.*;
import com.droidclaimsurveyor.helper.service.DateDeserializer;
import com.droidclaimsurveyor.helper.service.RestfulWebService;
import com.droidclaimsurveyor.helper.service.ServiceMethod;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class UpdateSurveyorLocation extends ServiceMethod<UpdateSurveyorLocationResultBlDto>{
	public static String METHOD_NAME = "UpdateSurveyorLocation";
	private Gson gson;
	private SurveyorLocationBlDto parameter;
	
	public UpdateSurveyorLocation(){
		 gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateDeserializer())
				 		.serializeNulls()
				 		.setDateFormat(DateFormat.LONG)
				 		.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
				 		.setPrettyPrinting()
				 		.create();
	}
	
	@Override
	public String getName() {
		return UpdateSurveyorLocation.METHOD_NAME;
	}

	@Override
	public String getParameter() {
		String result = "";
		
		result = gson.toJson(parameter);
				
		return result;
	}

	public void setParameter(SurveyorLocationBlDto parameter) {
		this.parameter = parameter;
	}
	
	@Override
	public int getMethodType(){
		return RestfulWebService.HTTP_POST;
	}
	
	public UpdateSurveyorLocationResultBlDto mapResponse(String json){
		if(json.isEmpty()){
			return new UpdateSurveyorLocationResultBlDto();
		}
		
		Type listType = new TypeToken<UpdateSurveyorLocationResultBlDto>(){}.getType();
		UpdateSurveyorLocationResultBlDto result = gson.fromJson(json, listType);
		
		return result;
	}
}
